<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="ookweb.Conn"%>
<%@ page import="ookweb.Data"%>
<%@ include file="../public.jsp" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ookweb/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">    
    <title>用户留言</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/images/m/css.css">
	<script src="<%=basePath%>js/jquery-1.5.1.min.js"  type="text/javascript" ></script>
	<script src="<%=basePath%>js/public.js"  type="text/javascript" ></script>
  </head>
  
  <body><br/>
  <%   Data data=new Data(dbuser,dbpass,dburl);
     Conn con=new Conn(dbuser,dbpass,dburl);
     String msgid=(String)request.getParameter("msgid");
    String act=(String)request.getParameter("act"); 
   
    //分页段 
     //变量声明 
String mysql=new String(); //SQL语句
mysql=" web_usermsg ";
int intRowCount=0;  //总的记录数
int intPageCount=0; //总的页数
int intPageSize=15; //每页显示的记录数
int intPage; //待显示页码 
String strPage=new String(); //用来接收当页码参数
int begin_no=0; //开始的rownum记录号
int end_no=0;  //结束的rownum记录号

//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//得到总的数据记录行数
intRowCount=data.getRowCount(mysql); //总记录数

//计算总共要分多少页
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 

if(intPage>intPageCount) intPage = intPageCount; 
//分页段
    int intT=0;
    if("d".equals(act) && !("".equals(msgid)) && msgid!=null){
       data.delete("delete from web_usermsg where msgid="+msgid);
       act=""; 
     }
    if(!("".equals(act) ||  act==null)){
       String content="",title="";
      if("save".equals(act)){
          String sql="";
          content=(String)request.getParameter("content");
          title=(String)request.getParameter("title");
         
         int num=0;
         
         if(!("".equals(msgid)) && msgid!=null){
	         sql="update web_usermsg set title='"+title+"',content='"+content+"' where msgid="+msgid;
	         num=data.update(sql);
	         if(num>0){out.print("<script>alert(\"已成功修改\");</script>");}
         }
         response.sendRedirect(basePath+"webadmin/member/msg.jsp?msgid="+msgid+"&page"+intPage);
      }else if("e".equals(act) && !("".equals(msgid)) && msgid!=null){	       
			 ResultSet rs=con.getRs("SELECT * FROM web_usermsg where msgid="+msgid);
			 if(rs.next()){
			 title=rs.getString("title");
			 msgid=rs.getString("msgid");
			 content=rs.getString("content");
			
			 }
      }else{msgid="";}
      %>
      <script src="<%=basePath%>ckeditor/ckeditor.js"  type="text/javascript" ></script>
      <script type="text/javascript" src="<%=basePath%>ckfinder/ckfinder.js"></script>
      
      <form action="<%=basePath%>webadmin/member/msg.jsp?act=save&msgid=<%=msgid %>&page=<%=intPage %>" method="post" id="frm">
	  <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
	   <tr>
	    <td align="center" width="140">标题</td>
	    <td align="left"><input name="title" id="title" style="width:400px;" type="text" class="inp" value="<%=title %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">内容</td>
	    <td align="left"><textarea name="content" ><%=content %></textarea>
	    <script type="text/javascript">
			        var editor=CKEDITOR.replace('content');
			         CKFinder.SetupCKEditor(editor,'<%=basePath%>editor/ckfinder/'); 
			  </script>
	    
	    </td>
	  </tr>
	   <tr>
	    <td align="center" width="140">操作</td>
	    <td align="left"> <input name="cmd" id="savecmd" type="button" class="inp" value="保存" style="width:60px;"/> <input name="cmd" id="cmdreturn" type="button" class="inp" value="返回" style="width:60px;"/></td>
	  </tr>
	 </table>
	 </form>
   <script type="text/javascript">
	$(document).ready(function() {
		$('#savecmd').click(function() {
		  if($('#title').attr('value')==''){
		  alert('请输入标题');return;
		  }else{
		    $("#frm").submit();
		  }
		});
		$('#cmdreturn').click(function() {
		window.history.back();
		});
	});
   </script>
   <% }else{%>
   <script type="text/javascript"> 
        var GB_ROOT_DIR = "<%=basePath%>images/m/greybox/";
	</script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/AJS.js"></script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/AJS_fx.js"></script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/gb_scripts.js"></script>
	<link href="<%=basePath%>images/m/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
  【<span class="bt">留言信息管理</span>】

 <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
  <tr>
    <th width="80">标题</th>
    <th width="140">用户</th>
    <th width="140">留言时间</th>
    <th width="140">操作</th>
  </tr>
  <% 
	    begin_no=(intPage-1) * intPageSize + 1; 
        end_no = intPage * intPageSize;
	    mysql="select a.*,b.username from (select rownum row_id ,userid,msgid,title,addtime from (select msgid,userid,title,addtime from web_usermsg  order by msgid desc)) a";
	    mysql=mysql+" left join web_member b on a.userid=b.mid where row_id between " +begin_no+ " and " +end_no;
	   //out.print(mysql);
	    ResultSet rs=con.getRs(mysql);
		int i=0;
		String title="";
		String siid="";
		while(rs.next()){
		i++;title=rs.getString("title");
		siid=rs.getString("msgid");
	 %>
	<tr onmouseover='$(this).css({"background":"#cee1ed"});' onmouseout='$(this).css({"background":"#fff"});'>
    <td  width="140"><%=rs.getString("title")%></td>
    <td  align="center"><%=rs.getString("username") %></td>
    <td width="140" align="center"><%=rs.getDate("addtime") %></td>
    <td width="140" align="center">
    <span class="area"><a title="留言回复列表" rel="gb_page_center[700,300]"  href="<%=basePath%>webadmin/member/reply.jsp?page=<%=intPage %>&msgid=<%=siid%>"> 回复 </a></span>
    <span class="area"><a   href="<%=basePath%>webadmin/member/msg.jsp?act=e&page=<%=intPage %>&msgid=<%=siid%>"> 编辑 </a></span> 
    <span class="area"><a href="javascript:confirmDelete('<%=basePath%>webadmin/member/msg.jsp?act=d&msgid=<%=siid%>&page=<%=intPage %>');"> 删除 </a></span></td>
    </tr>
   <%} 
   if(intPageCount>1){
   %>
   <tr>
    <td colspan="5" align="center">
     第<%=intPage%>页 共<%=intPageCount%>页 
<a href="<%=basePath%>webadmin/member/msg.jsp?page=1">首页</a>
<%if(intPage>1){%><a href="<%=basePath%>webadmin/member/msg.jsp?page=<%=intPage-1%>">上一页</a><%}%> 
<%if(intPage<intPageCount){%><a href="<%=basePath%>webadmin/member/msg.jsp?page=<%=intPage+1%>">下一页</a><%}%> 
<a href="<%=basePath%>webadmin/member/msg.jsp?page=<%=intPageCount%>">尾页</a>
   </td>
   </tr>
   <%} %>
 </table>
 <% } con.close();%>
  </body>
</html>
